﻿@using System.Data;
@using GatewayServer.Common;
@using UtilsBase;
@{
    ViewBag.PageTitle = "洪峰智能";

    Layout = "~/Views/Shared/PageTemplate.cshtml";
}

<script>
    $(document).ready(function () {

        if ("@(ViewBag.order)" == "upd") {
            getEdit("@(ViewBag.p_guid)");

        }

    });


    function getEdit(pguid) {
        $.post("getProduct", { "flag": Math.random(), guid: pguid }, function (result) {
            var myobj = (result.data);
            $("#p_name").val(myobj.p_name);
            $("#p_scene_name").val(myobj.p_scene_name);
            
            for (var i = 0; i < document.getElementById("p_status").options.length; i++) {
                if (document.getElementById("p_status").options[i].value == myobj.d_status) {
                    document.getElementById("p_status").options[i].selected = true;
                    break;
                }
                else {
                    document.getElementById("p_status").options[i].selected = false;

                }
            }
        });
    }
    function saveAll() {
        var data = $("#addForm").serializeArray(); //自动将form表单封装成json
        $.post("saveAll", data, function (result) {
            var jsonresult = (result);

            if (jsonresult.respCode == "200") {
                // $("#result").text("操作完成");
                  window.location.href = "list";
                // window.history.back();
                alert("保存成功");
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }
        });
    }

    function del()
    {
        if(!confirm("确认删除吗？"))
        {
            return;
        }
      
        var data =null;// $("#addForm").serializeArray(); //自动将form表单封装成json
        $.post("del?guid=@(ViewBag.p_guid)", data, function (result) {
            var jsonresult = (result);

            if (jsonresult.respCode == "200") {
                window.location.href = "list";
                alert("删除成功");
            }
            else {
                alert(jsonresult.respMsg);
                return;
            }
        });

    }
</script>

<style>
    #pagelist_follow {
        width: 100%;
    }

    #pagelist_main {
        width: 100%;
    }

    .kv-item label {
        width: 150px;
    }
</style>
<div id="saper-container">
    <form id="addForm" name="addForm" action="list" method="post">
        <input type="hidden" name="p_guid" id="p_guid" value="@ViewBag.p_guid" />
        <div id="saper-hd"></div>
        <div id="saper-bd">
            <div class="subfiled clearfix">
                <h2>产品添加/编辑</h2>
            </div>
            <div class="subfiled-content">

                <div id="" title="添加/编辑">
                    <form action="" name="addForm" id="addForm" method="post">
                      
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>产品名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="p_name" id="p_name" placeholder="名称"  />

                            </div>
                        </div>
                         <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>应用场景名称：</label>
                            <div class="kv-item-content">
                                <input type="text" name="p_scene_name" id="p_scene_name" placeholder="应用场景名称" />

                            </div>
                        </div>
                        <div class="kv-item clearfix">
                            <label><span class="impInfo">*</span>状态：</label>
                            <div class="kv-item-content">
                                <select id="p_status" name="p_status" style="width:130px;">
                                    <option value="0">启用</option>
                                    <option value="1">禁用</option>
                                </select>

                            </div>
                        </div>

                        <div><hr /></div>
                        <div style="margin:0 auto;width:150px;">

                            <input type="button" id="save" name="save" value="保存" onclick="javascript:saveAll()" />
                            &nbsp;&nbsp; <input type="button" id="but_back1" name="but_back1" value="返回" onclick="javascript:window.history.back()" />

                            &nbsp;&nbsp;<a href="javascript:del()">删除</a>
                        </div>

                    </form>
                </div>
            </div>
        </div>
        <div id="saper-ft"></div>
    </form>
</div>

